
Ext.onReady(function(){
	 function addTab (closable,text,pid,url) {
	 	
	 	for (var i = 0; i < viewTabPanel.items.length; i++) {
	 		if(viewTabPanel.items.items[i].title==text){
	 			viewTabPanel.setActiveTab(viewTabPanel.items.items[i]);
	 			return;
	 		}
	 	}
	 	
	 	var userid=Ext.get('mainuserid').getValue();
		
	 	if(userid==null){
	 		return ;
	 	}
	 	url=url+'?userid='+userid;
        viewTabPanel.add({
            title: text, 
            closable: closable,
            html:'<iframe scrolling="auto" id="f'+pid+'" frameborder="0" width="100%" height="100%" src="'+url+'"> </iframe>',
            listeners:{
				'close':function(){
					if(Ext.get('f'+pid)){
						Ext.get('f'+pid).dom.removeChild;
						Ext.get('f'+pid).dom.src=null;
					}
				}
			}
        }).show();

    }
    var usersname=Ext.get('mainSname').getValue();
    var menuTree = new Ext.tree.TreePanel({
        rootVisible: false,
        frame: true,
        width:200,
		region:'west',
        title:'欢迎您: '+usersname,
        useArrows: true,
        autoScroll: true,
        animate: true,
        enableDD: true,
        containerScroll: true,
        collapsible: true,
        border:false,
        loader:new Ext.tree.TreeLoader({
        	dataUrl:'menuData.do',
        	preloadChildren:true
        }),
        root: {
        	nodeType: 'async',
            text: 'Ext JS',
            draggable: false,
            id: 'src'
        },
        listeners:{
        	
        	click:function(node,event){
        		if(node.leaf==true){
        			addTab(true,node.text,node.id,node.attributes.url);
        		}
        	}
        }       
    });
    
	var viewTabPanel=new Ext.TabPanel({
		region:'center'
	});

	var mainPanel = new Ext.Viewport({
		id:'mainPanel',
		layout:'border',
		items:[viewTabPanel,menuTree],
		listeners: { 
	        'resize': function(viewport,adjWidth,adjHeight,rawWidth,rawHeight)  {
	          	Ext.getCmp("mainPanel").setHeight((document.body.clientHeight - 290) * 0.67);  
			}
		}
	});
	
	mainPanel.render('mainDIV');
})

function enterkey(e,i){
	    if (i==8){
	      event.keyCode=0;
	      event.returnValue=false;
	      return false;
	    }
}